<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            报工数据
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工单号</div>
                    <input type="text" class="aui-input" id="workOrderCode" disabled="true">
                </div>
            </li>
        </ul>

        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="revocation()">撤销</div>
        <div style="width:100%;margin-top:2%;"></div>

        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="toPrint()">补打</div>
        <div style="width:100%;margin-top:2%;"></div>
        <div
            style="background-color:white; width: 100%;margin-top:2%;white-space: nowrap;overflow-x: auto;-webkit-overflow-scrolling:touch;">

            <table class="table" style='width:1000px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style="width:40px;"></td>
                        <td algin='center' style="width:50px;">序号</td>
                        <td algin='center' style="width:130px;">箱号</td>
                        <td algin='center' style="width:130px;;">批次号</td>
                        <td algin='center' style="width:100px;">数量</td>
                        <td algin='center' style="width:100px;">不良品数量</td>
                        <td algin='center' style="width:100px;">报工类型</td>
                        <td algin='center' style="width:150px;">报工时间</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:1000px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 700px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var scanRule = ""; //条码解析规则
    var address = ""

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //初始化查询仓库下拉框
    apiready = function () {
        $("#workOrderCode").val(api.pageParam.workOrderCode);
        address = api.pageParam.address;
        search();

    }



    //查询表格数据
    function search() {
        var workOrderCode = $("#workOrderCode").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkOrderCXtable";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workOrderCode: workOrderCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {

                    var list = eval(myobj.list);

                    var html = "";

                    //发货单明细数据存在
                    if (list.length > 0) {
                        // 箱号、批次号、数量、报工类型、报工时间

                        //遍历
                        for (var i = 0; i < list.length; i++) {
                            html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                            html += "<td style='width:40px;'><input name='sub' type='checkbox'/></td>";
                            html += "<td name='seqNo' style='width:50px;'>" + (i + 1) + "</td>";
                            html += "<td name='ext05' style='width:130px;'>" + list[i].ext05 + "</td>";
                            html += "<td name='lotCode' style='width:130px;'>" + list[i].lotCode + "</td>";
                            html += "<td name='qyt' style='width:100px;'>" + list[i].qyt + "</td>";
                            
                            if (list[i].ext03 == null) {
                                html += "<td name='ext03' style='width:100px;'>" + '0' + "</td>";
                            }else{
                                html += "<td name='ext03' style='width:100px;'>" + list[i].ext03 + "</td>";
                            }
                            if (list[i].finishType == '1') {
                                html += "<td name='finishType' style='width:100px;'>" + '手动报工' + "</td>";
                            } else if (list[i].finishType == '2') {
                                html += "<td name='finishType' style='width:100px;'>" + '自动报工' + "</td>";
                            }

                            html += "<td name='createDate' style='width:150px;'>" + list[i].createDate + "</td>";

                            html += "</tr>";
                        }

                    } else {

                    }

                    $api.html($api.byId("tbodyHtml"), html);

                    //失败，存在没有订单数据
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }


    //补打
    function toPrint() {
        var opCode = api.pageParam.opCode
        if (address == null || address == "" || address == undefined) {
            api.toast({
                msg: "请选择蓝牙！"
            });
            return;
        }
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var boxnum = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            boxnum = row.find("[name='ext05']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: '请选择一条表格数据！',
                duration: 3000
            });
            return;
        }
        localStorage.setItem('bluetooth', address);

        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/tmBoxnumPlatform2";
        var data = {
            values: {
                opCode: opCode,
                boxnum: boxnum,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {

                    //返回json数据
                    var json = myobj.json;

                    //调用PDA打印
                    printPDA(json, address);

                } else {

                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {

                $("#boxnum").val("");
                alert(JSON.stringify(err));
            }
        });
    }

    //打印
    function printPDA(json, address) {
        var modulePrinterCpclDJG = api.require('modulePrinterCpclDJG');
        modulePrinterCpclDJG.printerPlatformBG({
            json: json, //打印数据JSON
            address: address //蓝牙地址
        }, function (ret, err) {
            if (ret) {

                if (ret.code == "S") {
                    api.toast({
                        msg: "打印成功"
                    });

                } else {
                    api.toast({
                        msg: ret.message
                    });
                }
            } else {

                alert(JSON.stringify(err));
            }
        });
    }

    function revocation() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var boxnum = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            boxnum = row.find("[name='ext05']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: '请选择一条表格数据！',
                duration: 3000
            });
            return;
        }
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/revocation";
        var data = {
            values: {
                boxnum: boxnum,
                un: un
            }
        };
        api.showProgress({
            title: '撤销中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    search();
                    api.toast({
                        msg: '撤销成功!',
                        duration: 3000
                    });

                    //失败，存在没有订单数据
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
                api.hideProgress();
            }
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>